package com.ysm.smfu.food.presenter;

import android.content.Context;

import com.ysm.smfu.bean.FoodStore;
import com.ysm.smfu.bean.KeyValueBean;
import com.ysm.smfu.food.model.FoodMainModeImp;
import com.ysm.smfu.food.model.FoodMainModel;
import com.ysm.smfu.food.view.FoodMainView;
import com.ysm.smfu.utils.ThreadUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/26.
 */
public class FoodMainPersenterImp implements FoodMainPersenter {

    private final FoodMainModel foodMainModeImp;
    private final FoodMainView foodMainView;

    public FoodMainPersenterImp(FoodMainView foodMainView) {
        this.foodMainView = foodMainView;
        foodMainModeImp = new FoodMainModeImp();
    }

    @Override
    public void showOriginalData() {
        foodMainModeImp.getFoodData(new FoodMainModeImp.CallBack() {
            @Override
            public void onSuccess(List<FoodStore> foodStoreList) {
                foodMainView.showOriginalPage(foodStoreList);
            }

            @Override
            public void onFail() {

            }

            @Override
            public void onGetData(List<KeyValueBean> smartData, List<KeyValueBean> listAll, List<KeyValueBean> mParentLists, List<ArrayList<KeyValueBean>> mChildrenListLists) {

            }
        });
    }

    @Override
    public void flushData() {
        foodMainModeImp.flushData(new FoodMainModeImp.CallBack() {
            @Override
            public void onSuccess(List<FoodStore> foodStoreList) {
                foodMainView.flushPage(foodStoreList);
            }

            @Override
            public void onFail() {

            }

            @Override
            public void onGetData(List<KeyValueBean> smartData, List<KeyValueBean> listAll, List<KeyValueBean> mParentLists, List<ArrayList<KeyValueBean>> mChildrenListLists) {

            }
        });
    }

    @Override
    public void loadMoreData() {
        foodMainModeImp.loadMoreData(new FoodMainModeImp.CallBack() {
            @Override
            public void onSuccess(List<FoodStore> foodStoreList) {
                if (foodStoreList != null && foodStoreList.size() > 0)
                    foodMainView.loadMorePageSuccess(foodStoreList);
                else if (foodStoreList == null)
                    foodMainView.loadMorePageFail();
                else if (foodStoreList != null && foodStoreList.size() == 0)
                    foodMainView.noMoreData();
            }

            @Override
            public void onFail() {

            }

            @Override
            public void onGetData(List<KeyValueBean> smartData, List<KeyValueBean> listAll, List<KeyValueBean> mParentLists, List<ArrayList<KeyValueBean>> mChildrenListLists) {

            }
        });
    }

    @Override
    public void loadRecommed() {
        foodMainView.initRecommed(null);
    }


    @Override
    public void addPopuView(Context context) {
        foodMainModeImp.getPopuData(context, new FoodMainModeImp.CallBack() {
            @Override
            public void onSuccess(List<FoodStore> foodStoreList) {

            }

            @Override
            public void onFail() {

            }

            @Override
            public void onGetData(final List<KeyValueBean> smartData, final List<KeyValueBean> listAll, final List<KeyValueBean> mParentLists, final List<ArrayList<KeyValueBean>> mChildrenListLists) {
                ThreadUtils.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        foodMainView.addItemToPopuView(smartData, listAll, mParentLists, mChildrenListLists);
                    }
                });
            }
        });
    }

}
